package socketmvc.core.config;

import socketmvc.core.codec.IPacketCodec;
import socketmvc.core.codec.ProtocolCodecHandler;
import socketmvc.core.filter.FilterHandler;
import socketmvc.core.filter.IFilter;
import socketmvc.core.processor.ProcessorMethodHandler;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

public class DefaultSocketMvcConfig implements SocketMvcConfig {
    ProcessorMethodHandler methodHandler;
    ProtocolCodecHandler codecHandler;
    FilterHandler filterHandler;
    Set<String> scanPackage = new HashSet<>();

    @Override
    public IpConfig getIpConfig() {
        return new DefaultWsIpConfig();
    }

    /**
     * 获取扫描处理器的包路径
     *
     * @return 包路径
     */
    @Override
    public Set<String> getProcessorScanPackage() {
        return scanPackage;
    }

    /**
     * 获取过滤器
     *
     * @return
     */
    @Override
    public Collection<IFilter> getFilters() {
        return null;
    }

    /**
     * 获取数据包编解码器
     *
     * @return Codecs
     */
    @Override
    public Collection<IPacketCodec> getPacketCodecs() {
        return null;
    }


    @Override
    public ProcessorMethodHandler getProcessorMethodHandler() {
        if (methodHandler == null){
            methodHandler = new ProcessorMethodHandler();
        }
        return methodHandler;
    }

    @Override
    public ProtocolCodecHandler getProtocolCodecHandler() {
        if (codecHandler == null){
            codecHandler =  new ProtocolCodecHandler();
        }
        return codecHandler;
    }

    @Override
    public FilterHandler getFilterHandler() {
        if (filterHandler == null){
            filterHandler = new FilterHandler();
        }
        return filterHandler;
    }


    public static class DefaultWsIpConfig implements IpConfig{

        @Override
        public boolean isEnable() {
            return true;
        }

        @Override
        public IpConfigType getType() {
            return IpConfigType.WEB_SOCKET;
        }

        @Override
        public String getId() {
            return String.valueOf(getPort());
        }

        @Override
        public String getHost() {
            return null;
        }

        @Override
        public int getPort() {
            return 6790;
        }

        @Override
        public SSL getSsl() {
            return null;
        }
    }
}
